home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / patchSG0003911.idb / usr / include / libXlate.h.z / libXlate.h
C/C++ Source or Header  |  2001-01-10  |  11KB  |  327 lines

  1. #ifndef _LIBXLATE_H
  2. #define _LIBXLATE_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /*
  8.     libXlate.h
  9.  
  10.     $Revision: 1.13 $
  11.  
  12.     All external symbols  and macros begin with one of the following
  13.     XLATE_
  14.        _XLATE_
  15.     xlate_
  16.     _xlate_
  17.  
  18.     Link in the functions with -lelfutil
  19.  
  20. */
  21.  
  22. #include <libelf.h> /* sets _LIBELF_XTND_EXPANDED_DATA if appropriate */
  23. #include <dwarf.h>
  24. #include <libdwarf.h>
  25.  
  26. #ifndef _XLATE_TABLEKIND_DEF
  27. #define _XLATE_TABLEKIND_DEF
  28. typedef enum {    
  29.         xlate_tk_general,
  30.         xlate_tk_preserve_size,
  31.         xlate_tk_preserve_order
  32. } xlate_tablekind;
  33. #endif
  34.  
  35. #ifdef _LIBELF_XTND_EXPANDED_DATA
  36. #define xlate_init_fd                   _xlate_init_fd_xtnd
  37. #define xlate_init_elf                  _xlate_init_elf_xtnd
  38. #define xlate_named_init_fd             _xlate_named_init_fd_xtnd
  39. #define xlate_named_init_elf            _xlate_named_init_elf_xtnd
  40. #define xlate_get_info                  _xlate_get_info_xtnd
  41. #define xlate_address                   _xlate_address_xtnd
  42. #define xlate_get_reg_rule              _xlate_get_reg_rule_xtnd
  43. #define xlate_get_all_reg_rules         _xlate_get_all_reg_rules_xtnd
  44. #define xlate_expand_reg_info           _xlate_expand_reg_info_xtnd
  45. #define xlate_expand_reg_info2          _xlate_expand_reg_info2_xtnd
  46. #define xlate_finish                    _xlate_finish_xtnd
  47.  
  48. #define xlate_pro_init                  _xlate_pro_init_xtnd
  49. #define xlate_pro_add_info              _xlate_pro_add_info_xtnd
  50. #define xlate_pro_add_reg_info          _xlate_pro_add_reg_info_xtnd
  51. #define xlate_pro_add_range             _xlate_pro_add_range_xtnd
  52. #define xlate_pro_disk_header           _xlate_pro_disk_header_xtnd
  53. #define xlate_pro_disk_next_block       _xlate_pro_disk_next_block_xtnd
  54. #define xlate_pro_finish                _xlate_pro_finish_xtnd
  55. #endif
  56.  
  57.  
  58. /*
  59.     We use different opaque structs as handles for the 
  60.     Producer and Consumer.
  61. */
  62. typedef struct xlate_table_con_s  *xlate_table_con;
  63. typedef struct xlate_table_pro_s  *xlate_table_pro;
  64.  
  65. /*
  66.     This struct is used to return pieces of the fully expanded
  67.     table to the user.  It is used to return the ranges that
  68.     correspond to a given contiguous range.
  69.  
  70.     Shared by all versions.
  71. */
  72. typedef struct xlate_block_s {
  73.     Elf64_Addr        xe_new_address;
  74.     Elf64_Xword        xe_new_range;
  75.     Elf64_Addr        xe_old_address;
  76.     Elf64_Xword        xe_old_range;
  77. } xlate_block;
  78.  
  79.  
  80. /******************** Consumer Interface *************************/
  81.  
  82. #define XLATE_OPEN_STD_TABLE   0
  83. #define XLATE_OPEN_DEBUG_TABLE 1
  84.  
  85. int xlate_init_fd(int    /*fd*/,
  86.     int            /*open_debug_table*/,
  87.     xlate_table_con *    /*returned_table_pointer*/);
  88.  
  89. int xlate_init_elf(Elf    * /*elf*/,
  90.     int              /*open_debug_table*/,
  91.     xlate_table_con *      /*table*/);
  92.  
  93. int xlate_named_init_fd(int /*fd*/,
  94.     const char *        /*section_name*/,
  95.     xlate_table_con *        /*returned_table_pointer*/);
  96.  
  97. int xlate_named_init_elf(Elf * /*elf*/,
  98.     const char *           /*section_name*/,
  99.     xlate_table_con *           /*table*/);
  100.  
  101. int xlate_get_info(xlate_table_con /*table*/,
  102.     Elf64_Sxword *      /*dataMoved*/,
  103.     Elf64_Addr *    /*new_low_addr*/,
  104.     Elf64_Addr *    /*old_low_addr*/,
  105.     Elf64_Addr *    /*new_high_addr*/,
  106.     Elf64_Addr *    /*old_high_addr*/,
  107.     Elf64_Addr *    /*startup_fwa*/,
  108.     Elf64_Addr *    /*startup_lwa*/,
  109.     Elf64_Xword *       /*number_of_ranges*/,
  110.     int         *        /*old_text_exists*/,
  111.     int         *    /*old_text_alloc*/,
  112.     int        *       /*is64bit */,
  113.     xlate_tablekind *   /*tablekind */,
  114.     int        *       /*tableversion */);
  115.  
  116. #define XLATE_ADDRESS_INPUT_NEW_ADDRESS  1
  117. #define XLATE_ADDRESS_INPUT_OLD_ADDRESS  0
  118. int xlate_address(xlate_table_con /*table*/,
  119.     int           /*is_new_address*/,
  120.     Elf64_Addr     /*address_in*/,
  121.     Elf64_Addr *   /*address_out*/,
  122.     xlate_block *  /*range*/);
  123.  
  124. int xlate_get_reg_rule(xlate_table_con  /*table*/,
  125.     Elf64_Addr          /*pc*/,
  126.     Elf32_Word          /*reg*/,
  127.     Elf32_Word *    /*rule_register*/,
  128.     Elf64_Xword *    /*rule_offset*/,
  129.     Elf32_Word *    /*rule_is_offset*/);
  130.  
  131. int xlate_get_all_reg_rules(xlate_table_con  /*table*/,
  132.     Elf64_Addr          /*pc*/,
  133.     Dwarf_Regtable *    /*reg_table*/);
  134.  
  135. typedef struct xlate_reg_instr_s{
  136.     Dwarf_Small        sr_op;
  137.     Dwarf_Unsigned    sr_val1;
  138.     Dwarf_Unsigned    sr_val2;
  139. } xlate_reg_instr;
  140.  
  141. /* xlate_expand_reg_info is obsolescent call: 
  142. ** use xlate_expand_reg_info2 instead.
  143. */
  144. int xlate_expand_reg_info(xlate_table_con  /*table*/,
  145.     Elf64_Xword *    /*num_instrs*/,
  146.     xlate_reg_instr **    /*instructions*/);
  147.  
  148. /*  xlate_reg_instr2_s is identical to
  149. **  xlate_reg_instr_s except it has a new field and
  150. **  uses a new interface function
  151. **  to preserve binary compatibility for old xlate_expand_reg_info 
  152. **  calling  code.
  153. **  The sr_instr_offset is the byte offset in the register instructions
  154. **  of the register instruction involved.
  155. */
  156. typedef struct xlate_reg_instr2_s{
  157.     Dwarf_Small        sr_op;
  158.     Dwarf_Unsigned    sr_val1;
  159.     Dwarf_Unsigned    sr_val2;
  160.     Dwarf_Unsigned      sr_instr_offset;
  161. } xlate_reg_instr2;
  162.  
  163. int xlate_expand_reg_info2(xlate_table_con  /*table*/,
  164.     Elf64_Xword *    /*num_instrs*/,
  165.     xlate_reg_instr2 **    /*instructions*/);
  166.  
  167. int xlate_finish(xlate_table_con /*table*/);
  168.  
  169.  
  170. /***************** special rqs interface *******************/
  171.  
  172. /*
  173.    Interface to xlate section fixer.
  174.    Called only by rqs.
  175.    Updates the bytes pointed to by pxlate, which must
  176.    be a valid .MIPS.xlate section (read in by the caller).
  177.    This routine does no file io and writes no messages.
  178.  
  179.    Returns value indicating success/failure.
  180.  
  181.    Returns XLATE_TB_STATUS_NO_ERROR 
  182.    in case of successful updating.
  183.  
  184.    Returns XLATE_TB_STATUS_INVALID_TABLE
  185.     if the table passed in is improper (perhaps partly trashed).
  186.  
  187.    Returns XLATE_TB_STATUS_XLATE_BAD  if the table has an improper
  188.     version number.
  189.  
  190.    Updating can only fail if the section is illogical/incomplete
  191.    (corruputed in some way).
  192.  
  193. */
  194. int _xlate_fix_addresses_for_dso_movement(
  195.         void*                pxlate,  /* memory address of the section:
  196.                         The caller must read or map in the section
  197.                         and pass pxlate as
  198.                         a pointer to the memory.
  199.             No particular alignment of the section
  200.             in memory is required by this routine.
  201.                         */
  202.         unsigned long long len, /* Length of the xlate
  203.                                 section.  If largerthan
  204.                                 the space pointed to by pxlate
  205.                                 chaos will surely follow*/
  206.         unsigned long long movement /* Amount that the 
  207.                                 text moved. 
  208.                         This value will be added to the appropriate
  209.                         vm addresses in the section. */
  210.                 );
  211.  
  212. /***************** Producer Interface *******************/
  213.  
  214. int xlate_pro_init(xlate_table_pro *     /*ret_table*/,
  215.     xlate_tablekind             /*tablekind*/,
  216.     xlate_table_con             /*compose_with_table*/,
  217.     int                     /*is64Bit*/);
  218.  
  219. int xlate_pro_add_info(xlate_table_pro /*table*/,
  220.     Elf64_Sxword         /*data_moved*/,
  221.     Elf64_Addr          /*startup_fwa*/,
  222.     Elf64_Addr          /*startup_lwa*/,
  223.     Elf32_Word          /*old_text_exists*/,
  224.     Elf32_Word          /*old_text_alloc*/);
  225.  
  226. int xlate_pro_add_reg_info(xlate_table_pro /*table*/,
  227.     Dwarf_Small         /*op*/,
  228.     Dwarf_Unsigned      /*val1*/,
  229.     Dwarf_Unsigned      /*val2*/);
  230.  
  231. int xlate_pro_add_range(xlate_table_pro /*table*/,
  232.     Elf64_Addr            /*new_address*/,
  233.     Elf64_Xword        /*new_range*/,
  234.     Elf64_Addr            /*old_address*/,
  235.     Elf64_Xword            /*old_range*/);
  236.  
  237. /* these are the legal values passed to xlate_pro_disk_header */
  238. #define XLATE_PRO_STANDARD_SETUP  1
  239. #define XLATE_PRO_DEBUG_SETUP     2
  240.  
  241. int xlate_pro_disk_header(xlate_table_pro  /*table*/,
  242.     int        /*standard_or_debug*/,
  243.     Elf64_Xword *    /*total_memory_req*/,
  244.     Elf64_Xword *    /*num_blocks*/);
  245.  
  246. int xlate_pro_disk_next_block(xlate_table_pro /*table*/,
  247.     char **        /*data*/,
  248.     Elf64_Xword *    /*data_size*/);
  249.  
  250.  
  251. int xlate_pro_finish(xlate_table_pro /*table*/);
  252.  
  253.  
  254. /***************** Return values *******************/
  255.  
  256.  
  257. /*
  258.   0 means no error.
  259.   All errors are negative numbers.  Defined here.
  260.   Positive number never returned.
  261. */
  262. #define XLATE_TB_STATUS_NO_ERROR        0
  263. #define XLATE_TB_STATUS_ALLOC_FAIL        -1
  264. #define XLATE_TB_STATUS_NULL_TABLE        -2
  265. #define XLATE_TB_STATUS_BAD_TABLEKIND        -3
  266. #define XLATE_TB_STATUS_BAD_ADD_ADDR        -4
  267. #define XLATE_TB_STATUS_RET_ADDR_NULL        -6
  268. #define XLATE_TB_STATUS_NO_MORE_BLOCKS        -7
  269. #define XLATE_TB_STATUS_NOT_YET_IMPLEMENT    -8
  270. #define XLATE_TB_STATUS_NO_DEBUG        -9
  271. #define XLATE_TB_STATUS_ALREADY_DONE        -10
  272.  
  273. #define XLATE_TB_STATUS_ADDR_UNALIGNED        -11
  274. #define XLATE_TB_STATUS_RANGE_BAD        -12
  275. #define XLATE_TB_STATUS_FSTAT_ERROR        -13
  276. #define XLATE_TB_STATUS_MMAP_ERROR        -14
  277. #define XLATE_TB_STATUS_BAD_VERSION        -15
  278. #define XLATE_TB_STATUS_NULL_HEADER        -16
  279. #define XLATE_TB_STATUS_NO_HEADER        -17
  280. #define XLATE_TB_STATUS_BAD_FILE_SIZE        -18
  281. #define XLATE_TB_STATUS_NEW_ADDR_ERROR          -19 /* unused */
  282. #define XLATE_TB_STATUS_DECODE_ERROR        -20
  283.  
  284. #define XLATE_TB_STATUS_BAD_BLOCK_INDEX        -21
  285. #define XLATE_TB_STATUS_UPPER_ADDR_BAD        -22
  286. #define XLATE_TB_STATUS_TABLE_NOT_PO        -23
  287. #define XLATE_TB_STATUS_MUNMAP_ERROR        -24
  288. #define XLATE_TB_STATUS_ELF_IDENT_BAD        -25
  289. #define XLATE_TB_STATUS_ELF_SHDR_BAD        -26
  290. #define XLATE_TB_STATUS_NO_XLATE        -27
  291. #define XLATE_TB_STATUS_NO_XLATE_DATA        -28
  292. #define XLATE_TB_STATUS_XLATE_BAD        -29
  293. #define XLATE_TB_STATUS_XLATE_DEBUG_BAD        -30
  294.  
  295. #define XLATE_TB_STATUS_ELF_VERSION_BAD        -31
  296. #define XLATE_TB_STATUS_ELF_BEGIN_BAD        -32
  297. #define XLATE_TB_STATUS_NOT_ELF            -33
  298. #define XLATE_TB_STATUS_OLD_ADDR_ERROR          -34 /* unused */
  299. #define XLATE_TB_STATUS_ADD_TOO_LATE        -35
  300. #define XLATE_TB_STATUS_BAD_REG_VAL        -36
  301. #define XLATE_TB_STATUS_BAD_REG_OP        -37
  302. #define XLATE_TB_STATUS_BAD_FRAME_OP        -38
  303. #define XLATE_TB_STATUS_NO_REG_INFO        -39
  304.  
  305. #define XLATE_TB_STATUS_SECTION_TOO_BIG         -42
  306. #define XLATE_TB_STATUS_INVALID_TABLE           -43
  307. #define XLATE_TB_STATUS_SECTION_TOO_SMALL       -44
  308. #define XLATE_TB_STATUS_INCONSISTENT_64_BIT_INFO -45
  309. #define XLATE_TB_STATUS_NO_SUCH_ADDR_IN_TABLE   -46
  310. #define XLATE_TB_STATUS_INVALID_BLOCK_INDEX     -47
  311. #define XLATE_TB_STATUS_REG_REQUEST_BOGUS         -48
  312. #define XLATE_TB_STATUS_PRO_CON_TABLE_MISMATCH     -59
  313. #define XLATE_TB_STATUS_PRO_REQ_INVALID     -50
  314. #define XLATE_TB_STATUS_BLOCK_REQ_SEQ_ERR     -51
  315. #define XLATE_TB_STATUS_FRAME_RESTORE_INVALID     -52
  316. #define XLATE_TB_STATUS_UNEQUAL_RANGE         -53
  317. #define XLATE_TB_STATUS_INVALID_PO_INPUT     -54
  318. #define XLATE_TB_STATUS_INVALID_SEQUENCE     -55
  319. #define XLATE_TB_STATUS_ELF_EHDR_BAD            -56
  320. #define XLATE_TB_STATUS_ELF_STRPTR_BAD          -57
  321.  
  322.  
  323. #ifdef __cplusplus
  324. }
  325. #endif
  326. #endif /* _LIBXLATE_H */
  327.